package com.neuedu.his.controller;

import com.neuedu.his.po.Patientcosts;
import com.neuedu.his.service.ChargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/charge")
public class ChargeController {

    @Autowired
    private ChargeService chargeService;

    // 根据病历号查询患者消费信息
    @GetMapping("/getbymid")
    public Map<String, Object> getByMid(@RequestParam("mid") Integer mid) {
        return chargeService.getByMid(mid);
    }

    // 收费结算
    @PostMapping("/chargeall")
    public Map<String, Object> chargeAll(@RequestBody Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        try {
            Integer mid = (Integer) params.get("mid");
            Double totalFee = (Double) params.get("totalFee");
            chargeService.chargeAll(mid, totalFee);
            result.put("code", 200);
            result.put("message", "收费成功");
        } catch (Exception e) {
            result.put("code", 500);
            result.put("message", "收费失败：" + e.getMessage());
        }
        return result;
    }
}